<?
$isReloadable = true;
$isPopUp = true;
require_once("../../pers/inc.config.php");
require_once(OVF_FS_WEB_ROOT."/app/_inc/inc.session.php");
require_once(OVF_FS_WEB_ROOT.'/app/_inc/funct.html.php');
$oDcorr = new ovfDate();
if (reqVarStr2date('dt')!==false) {
	$oDcorr = new ovfDate(reqVar('dt'));
}
if (reqVar('azione')=='onchange') {
	$oDcorr = new ovfDate("01/".reqVar('mese_sel')."/".reqVar('anno_sel'));
}
$oDcorr->day = 1;

$oDmesePrec = clone $oDcorr;
$oDmesePrec->setMonthAdd(-1);
$oDmeseSucc = clone $oDcorr;
$oDmeseSucc->setMonthAdd(+1);

$oDannoPrec = clone $oDcorr;
$oDannoPrec->year--;
$oDannoSucc = clone $oDcorr;
$oDannoSucc->year++;

$month = $oDcorr->month();
$year = $oDcorr->year();
$oDcorr->setDMY($oDcorr->weekFirst()); //////////////echo("inizio sett. = ".$oDcorr->getDMY());
?>
<html>
<head>
<meta Name="expires" content= "Mon, 1 Jan 2000 00:00:00 GMT"/>
<meta http-equiv="Pragma" content="no-cache"/>
<meta http-equiv="Cache-Control" content="no-cache"/>
<meta http-equiv="content-language" content="it">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
<title>Calendario</title>
<link rel="shortcut icon" href='../_img/ovf.ico' type="image/x-icon" />
</head>
<script>

function submNewDay(day) {
	document.frmCal.azione.value = 'precsucc';
	document.frmCal.dt.value = day;
	document.frmCal.submit();
}

function cambioMese() {
	document.frmCal.azione.value = 'onchange';
	document.frmCal.submit();
}

function setDateForm(val) {
	if ('<?=reqVar('nome_form')?>'=='') {
		alert("manca nome form !");
		return false;
	}
	if ('<?=reqVar('nome_campo')?>'=='') {
		alert("manca nome campo !");
		return false;
	}
	oFormOrig = window.opener.document.<?=reqVar('nome_form')?>;
	nomeCampo = '<?=reqVar('nome_campo')?>';
	if (!oFormOrig) {
		alert('finestra origine mancante');
		window.close();
		return false;
	}
	for($k=0; $k < oFormOrig.elements.length; $k++) {
		if (oFormOrig.elements[$k].name == nomeCampo) break;
	}
	if ($k >= oFormOrig.elements.length) {
		alert('non esiste campo '+nomeCampo);
		window.close();
		return false;
	}
	oField = oFormOrig.elements[$k];
	if (oField.type == "select-one") {
		lval = val.toLowerCase();
		//alert(nomeCampo+" ("+oField.type+") = "+lval);
		imax = oField.options.length;
		//alert("scorre "+imax);
		for(i=0; i < imax; i++) {
			//alert(oField.options[i].text+" - "+i+") "+oField.options[i].value+"="+val);
			if (lval == oField.options[i].value.toLowerCase()) {
				//alert("trovato "+oField.options[i].text+"-"+oField.options[i].value);
				oField.selectedIndex = i;
				break;
			}
		}
	} else {
		oField.value = val;
	}
	
	//alert(nomeCampo+'='+val);
	oField.focus();
	<?php if (reqVar('submOrig')=='S') echo "oFormOrig.submit();\n";?>
	window.close();
	return true;
}
</script>
<style type="text/css">
body {
   font-family:arial,helvetica;
   font-size: 8pt;
}
.tab1 {
   font-family:arial,helvetica;
   font-size: 8pt;
}
.lab1 {
   font-family:arial,helvetica;
   font-size: 8pt;
   font-weight:normal;
   color:#000000;
   background-color:#dddddd;
}
.lab2 {
   font-family:arial,helvetica;
   font-size: 8pt;
   font-weight:normal;
   color:#000000;
   background-color:#CACACA;
}
.txt1 {
   font-family:arial,helvetica;
   font-size: 8pt;
   color:#000000;
   background-color:#f8f8f8;
}

a.txt1:link, a.txt1:visited,a.txt1:active,a.txt1:hover {
   font-family:arial,helvetica;
   font-size: 8pt;
   color:#000000;
   background-color:#f8f8f8;
}

.txt2 {
   font-family:arial,helvetica;
   font-size: 8pt;
   color:#000000;
   background-color:#f0f0f0;
}

a.txt2:link, a.txt2:visited,a.txt2:active,a.txt2:hover {
   font-family:arial,helvetica;
   font-size: 8pt;
   color:#000000;
   background-color:#f0f0f0;
}

.inp1 {
   font-family:arial,helvetica;
   font-size: 8pt;
   border: 1px solid #808080;
   color:#000000;
   background-color:#ffffff;
}

.err1 {
   font-family:arial,helvetica;
   font-size: 8pt;
   font-weight:bold;
   color:#ff0000;
   background-color:#ffffff;
}

.cmd1,.cmd1:link,.cmd1:visited,.cmd1:active {
   font-family:arial,helvetica;
   font-size: 8pt;
   font-weight:bold;
   color:#808080;
}

.cmd1:hover {
   font-family:arial,helvetica;
   font-size: 8pt;
   font-weight:bold;
   color:#000000;
}

</style>
<body>
<div align='center'>
   <form name="frmCal" id='frmCal' action="<?=$_SERVER['PHP_SELF']?>" method="POST">
   <input type="hidden" name="xsn" value="<?=reqVarHE('xsn')?>">
   <input type="hidden" name="dt" value="<?=reqVarHE('dt')?>">
   <input type="hidden" name="azione" value="xxx">
   <input type="hidden" name="nome_form" value="<?=reqVarHE('nome_form')?>">
   <input type="hidden" name="nome_campo" value="<?=reqVarHE('nome_campo')?>">
   <input type="hidden" name="submOrig" value="<?=reqVarHE('submOrig')?>">
<table width='270' cellspacing='1' cellpadding='2' border='0'>
   <tr>
      <td colspan="7" class='lab1' align='center'><b><?=_t('CALENDARIO')?></b></td>
   </tr>
   <tr>
      <td colspan="7" class='lab1' align='center'>
      	<a href="#" class='cmd1' title='<?=_t('anno precedente')?>'
      		onClick="submNewDay('<?="01/".$oDannoPrec->month()."/".$oDannoPrec->year()?>')">
      		<b>&lt;&lt;&lt;</b>
      	</a>
      	&nbsp;&nbsp;&nbsp;
      	<a href="#" class='cmd1' title='<?=_t('mese precedente')?>'
      		onClick="submNewDay('<?="01/".$oDmesePrec->month()."/".$oDmesePrec->year()?>')">
      		<b>&lt;&lt;</b>
      	</a>
      	&nbsp;&nbsp;&nbsp;
      	<select class='txt1' name='mese_sel' id='mese_sel' onChange="cambioMese();">
<?
$aMesX = array('01'=>'gennaio','02'=>'febbraio','03'=>'marzo','04'=>'aprile','05'=>'maggio','06'=>'giugno'
	,'07'=>'luglio','08'=>'agosto','09'=>'settembre','10'=>'ottobre','11'=>'novembre','12'=>'dicembre');
foreach($aMesX as $mX => $sMx) {
	$sel = ($mX == $month)?'SELECTED':'';
?>
      		<option value="<?=$mX?>" <?=$sel?>><?=_t($sMx)?></option>
<?
}
?>
      		</select>
      		<select class='txt1' name='anno_sel' id='anno_sel' onChange="cambioMese();">
<?
$aAnni = array(intval($year));
for($annoX=1990; $annoX<=2020; $annoX++) {
	if (!in_array($annoX,$aAnni)) $aAnni[] = $annoX;
}
for($annoX=1905; $annoX<=2090; $annoX+=5) {
	if (!in_array($annoX,$aAnni)) $aAnni[] = $annoX;
}
sort($aAnni);
foreach($aAnni as $annoX) {
	$sel = ($annoX == intval($year))?'SELECTED':'';
?>
      			<option value="<?=$annoX?>" <?=$sel?>><?=$annoX?></option>
<?
}
?>
      		</select>
	      	&nbsp;&nbsp;&nbsp;
	      	<a href="#" class='cmd1' title='mese successivo'
	      		onClick="submNewDay('<?="01/".$oDmeseSucc->month()."/".$oDmeseSucc->year()?>')">
	      		<b>&gt;&gt;</b>
	      	</a>
	      	&nbsp;&nbsp;&nbsp;
	      	<a href="#" class='cmd1' title='anno successivo'
	      		onClick="submNewDay('<?="01/".$oDannoSucc->month()."/".$oDannoSucc->year()?>')">
	      		<b>&gt;&gt;&gt;</b>
	      	</a>
			</td>
	   </tr>
  		<tr>
	  		<td class='lab1' align='center' width='14%'><?=_t('lun')?></td>
	  		<td class='lab1' align='center' width='14%'><?=_t('mar')?></td>
	  		<td class='lab1' align='center' width='14%'><?=_t('mer')?></td>
	  		<td class='lab1' align='center' width='14%'><?=_t('gio')?></td>
	  		<td class='lab1' align='center' width='14%'><?=_t('ven')?></td>
	  		<td class='lab1' align='center' width='14%'><?=_t('sab')?></td>
	  		<td class='lab1' align='center' width='14%'><?=_t('dom')?></td>
	  	</tr>
<?
for($nRig=0; $nRig<6; $nRig++) {
	echo "<tr>\n";
	for($k=0; $k<7; $k++) {
		$stileDay = 'text-decoration:underline;cursor:pointer;';
		if ($oDcorr->isHoliday()) {
			$stileDay .= 'background-color:#d8d8d8;';
		} 
		if ($oDcorr->month() != $month) {
			$stileDay .= 'color:#808080;';
		} else {
			$stileDay .= 'font-weight:bold;';
		}			
		
		echo "<td class='txt1' align='center' style='".$stileDay."' ";
		echo "title='".$oDcorr->getDMY()."' ";
		echo "onClick=\"setDateForm('".$oDcorr->getDMY()."');\"";
		echo ">".$oDcorr->day()."</td>\n";
		$oDcorr->setDayAdd(1);
	} 
	//dbg_($oDcorr->getDMY());
	echo "</tr>\n";
} 
?>  
</table>
</form>	  	   	   
<a href="#" class='cmd1' title='<?=_t('vai al mese corrente')?>'
      onClick="submNewDay('<?=date("d/m/Y")?>')">
      <?=_t('mese corrente')?></a>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<a class='cmd1' title='chiudi calendario'
	href='javascript:window.opener.focus();window.close();'><?=_t('chiudi')?></a>
</div>
</body>
</HTML>
<?
/*
function reqVar($nome) {
   global $_REQUEST;
   if (!isset($_REQUEST[$nome])) return '';
   return (get_magic_quotes_gpc())?stripslashes($_REQUEST[$nome]):$_REQUEST[$nome];
}

function reqVarAS($nome) {
   return addslashes(reqVar($nome));
}

function reqVarHE($nome) {
   return htmlentities(reqVar($nome));
}
*/